!function() {
    
    // 获得基础JIPIN对象
    var JIPIN = window.__NS__JIPIN;
    if(!JIPIN) { return; }
    var $ = JIPIN.$;
    
    JIPIN._getSitePicDesc = JIPIN.getSitePicDesc;
    JIPIN.getSitePicDesc = function(targetPic) {
        if(isWaterfallPic(targetPic)) {
            return $.trim(targetPic.parent().next('.description').text()) || '';
        } else if(isDetailPic(targetPic)) {
            return $.trim($('#pin_caption p').first().text());
        } else {
            return JIPIN._getSitePicDesc(targetPic);
        }
    };
    
    JIPIN._fixImage = JIPIN.fixImage;
    JIPIN._refixImage = JIPIN.refixImage;
    
    JIPIN.getSourceURL = function(targetPic) {
        var url = document.location.href;
        if(isWaterfallPic(targetPic)) {
            url = targetPic.parent().get(0).href; 
        }
        return url;
    };
    
    JIPIN.fixImage = function(image, callback) {
        if(isWaterfallPic(image)) {
            callback(image);
        } else {
            this._fixImage(image, callback);
        }
    };
    
    JIPIN.refixImage = function(image, callback) {
        if(isWaterfallPic(image)) {
            callback(image);
        } else {
            this._refixImage(image, callback);
        }
    };
    
    function isWaterfallPic(pic) {
        return $(pic).parent().parent().is('div.pin');
    }
    
    function isDetailPic(pic) {
        return $(pic).parent().parent().is('#pin_img');
    }
    
}();